{% extends "admin/base.html" %}
{% block title %} 文章管理 {% endblock %}
{% block menu %}
    {% set menu_current = 'entry' %}
    {% include 'admin/menu.html' %}
{% endblock %}
{% block content %}
    <div id="where">当前位置：<span class="chosen">文章管理</span></div>
    <div id="entry" class="content">
        <div class="form-box">
            <form method="get" action="">
            <input type="text" name="q" class="text" value="{{ args['q'] }}" /> <select name="category"><option value="">所有分类</option>{% for i in categories %}<option value="{{i.id}}" {% if args['category']==i.id|string %}selected{% endif %}>{{i.title}}</option>{% endfor %}</select> <select name="status"><option value="">选择状态</option><option value="live" {% if args['status']=='live' %}selected{% endif %}>已发布</option><option value="draft" {% if args['status']=='draft' %}selected{% endif %}>草稿</option></select> 发布时间从 <input type="text" name="start_date" class="text datetime" value="{{ args['start_date'] }}" style="width:80px;" /> 到 <input type="text" name="end_date" class="text datetime" value="{{ args['end_date'] }}" style="width:80px;" /> <input type="submit" class="button" value="搜索" />
            </form>
        </div>
        <h3>{{ title }}</h3>
        <div class="data-list">
            <form method="post" action="./entry?next={{url}}">
            <table cellspacing="0">
            <thead>
                <tr>
                    <th><label><input type="checkbox" name="select_all" /></label></th>
                    <th style="width:25%;">标题</th>
                    <th style="width:25%;">Slug</th>
                    <th>分类</th>
                    <th>评论</th>
                    {% if session['user']['is_superuser'] %}<th>作者</th>{% endif %}
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            {% if p.object_list %}
                {% for i in p.object_list %}
                <tr class="{{ loop.cycle('odd', 'even') }}">
                    <td><input type="checkbox" name="e_id" value="{{ i.id }}" /></td>
                    <td><a href="../../entry/{{ i.slug }}" title="查看" target="_blank">{{ i.title }}</a></td>
                    <td>{{ i.slug }}</td>
                    <td>{% for j in i.categories %}<a href="#" title="">{{ j.title }}</a> {% endfor %}</td>
                    <td>{{ i.comments|count }}</td>
                    {% if session['user']['is_superuser'] %}<td>{{ i.blog_users.username }}</td>{% endif %}
                    <td>{{ i.status }}</td>
                    <td>
                    {% if i.author_id==session.user.id %}
                        <a href="entry/{{ i.id }}/edit" title="修改">编辑</a> <a href="javascript:;" url="entry/{{ i.id }}/del" class="del">删除</a>
                    {% elif session.user.is_superuser and i.status=='live' %}
                        <a href="entry/{{ i.id }}/back" title="设置当前文章为草稿">退稿</a>
                    {% endif %}
                    </td>
                </tr>
                {% endfor %}
            {% else %}
                <tr>
                    <td colspan="5"><p class="no-data">暂无记录</p></td>
                </tr>
            {% endif %}
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="7"><input type="submit" class="button" value="设置为草稿" /></td>
                </tr>
            </tfoot>
            </table>
            </form>
        </div>  
    </div>
{% endblock %}
{% block js %}
    <script language="JavaScript" type="text/javascript">
    <!--
    $(function(){
        $('a.del').click(function(){
            var url = $(this).attr('url');
            var r=confirm("确定要删除吗？");
            if (r==true) {
                location.href = url;
            }	
        })
        $('input[name=select_all]').click(function(){
            if ($(this).attr('checked')==true)
            {
                $(this).parents('table').find('input[type=checkbox]').attr('checked','checked');
            } else {
                $(this).parents('table').find('input[type=checkbox]').removeAttr('checked');
            }
        })
    })
    //-->
    </script>
{% endblock %}